import { constantRoutes, asyncRoutes } from '@/router'

const state = {
  routes: constantRoutes
}
const mutations = {
  setRoutes(state, otherRoutes) {
    // state.routes.concat(otherRoutes)  重复登录会一直添加权限
    state.routes = [
      ...constantRoutes,
      ...otherRoutes
    ]
  }
}
const actions = {
  filterRoutes(context, menus) {
    // 过滤
    const otherRoutes = asyncRoutes.filter(item => {
      return menus.includes(item.children[0].name)
    })

    context.commit('setRoutes', otherRoutes)

    return otherRoutes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
